#pragma once
#include <android/log.h>
#include <android/native_window.h>

#include <map>
#include <memory>

#include "include/completed_state.h"
#include "include/error_state.h"
#include "include/idle_state.h"
#include "include/initialized_state.h"
#include "include/paused_state.h"
#include "include/play_manager.h"
#include "include/player_state_code.h"
#include "include/playing_state.h"
#include "include/prepared_state.h"
#include "include/seeking_state.h"
#include "include/stop_state.h"
namespace codec {
class StateManager {
 private:
  using CallbackType =
      std::function<void(PlayerStateCode, std::map<std::string, std::string>)>;
  CallbackType callback_;
  std::unique_ptr<PlayerStateBase> currentState = std::make_unique<IdleState>();
  std::shared_ptr<PlayManager> playManager_ = std::make_shared<PlayManager>();

 public:
  void setDataSource(int fd);
  void setCallback(CallbackType cb);
  void notifyProgressChange(int);
  void notifyStateChange(PlayerStateCode code,
                         const std::map<std::string, std::string> &map);

  void prepare(ANativeWindow *window, const std::string &vertexCode,
               const std::string &fragmentCode);
  void start();
  void seekTo(float position);
  void pause();
  void resume();
  void release();
  void transitionTo(PlayerStateCode newState);
  void transitionTo(PlayerStateCode newState,
                    const std::map<std::string, std::string> &map);
  bool isValidTransition(PlayerStateCode oldState, PlayerStateCode newState);
};
}  // namespace codec